import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/login'
import Register from '@/components/register'
import ForgetPassword from '@/components/forget-password'
import Home from '@/components/home'
import { getToken } from '@/libs/utils'
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: Home,
      redirect: { name: 'home' },
      children: [
        {
          path: '/home',
          name: 'home',
          component: Home,
          beforeEnter(to, from, next) {
            let token = getToken()
            if (token) {
              next()
            } else {
              next({
                name: 'login'
              })
            }
          }
        },
      ]
    },
    {
      path: '/login',
      component: Login,
      name: 'login',
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/forget-password',
      name: 'forget-password',
      component: ForgetPassword
    },


  ]
})
